

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.CdcDevice;
import com.loong.loong.hik.service.CdcDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 疾控设备
 *
 * @author cs
 * @date 2023-04-13 17:00:39
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/cdcdevice" )
@Api(value = "cdcdevice", tags = "疾控设备管理")
public class CdcDeviceController {

    private final  CdcDeviceService cdcDeviceService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param cdcDevice 疾控设备
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_cdcdevice_view')" )
    public R getCdcDevicePage(Page page, CdcDevice cdcDevice) {
        return R.ok(cdcDeviceService.page(page, Wrappers.query(cdcDevice).lambda()
				.like(StringUtils.isNotEmpty(cdcDevice.getLikeName()), CdcDevice::getLabel,cdcDevice.getLikeName())
				.between(StringUtils.isNotEmpty(cdcDevice.getStartTime())&&StringUtils.isNotEmpty(cdcDevice.getEndTime()), CdcDevice::getCreateTime,cdcDevice.getStartTime(),cdcDevice.getEndTime()))
		);
    }


    /**
     * 通过id查询疾控设备
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_cdcdevice_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(cdcDeviceService.getById(id));
    }

    /**
     * 新增疾控设备
     * @param cdcDevice 疾控设备
     * @return R
     */
    @ApiOperation(value = "新增疾控设备", notes = "新增疾控设备")
    @SysLog("新增疾控设备" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_cdcdevice_add')" )
    public R save(@RequestBody CdcDevice cdcDevice) {
        return R.ok(cdcDeviceService.save(cdcDevice));
    }

    /**
     * 修改疾控设备
     * @param cdcDevice 疾控设备
     * @return R
     */
    @ApiOperation(value = "修改疾控设备", notes = "修改疾控设备")
    @SysLog("修改疾控设备" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_cdcdevice_edit')" )
    public R updateById(@RequestBody CdcDevice cdcDevice) {
        return R.ok(cdcDeviceService.updateById(cdcDevice));
    }

    /**
     * 通过id删除疾控设备
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除疾控设备", notes = "通过id删除疾控设备")
    @SysLog("通过id删除疾控设备" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_cdcdevice_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(cdcDeviceService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param cdcDevice 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_cdcdevice_export')" )
    public List<CdcDevice> export(CdcDevice cdcDevice) {
        return cdcDeviceService.list(Wrappers.query(cdcDevice));
    }
}
